
package atm.components;

/**
 * Represents printer component.
 */
public class Printer {

	private int privateconfirmationsLeftToPrint;

	public Printer() {
		setConfirmationsLeftToPrint(100);
	}

	/**
	 * Checks if there is enough paper in printer and printer is operating.
	 * 
	 * @return true if printer is ready to print
	 */
	public boolean checkPaper() {
		if (getConfirmationsLeftToPrint() > 0) {
			return true;
		}
		return false;
	}

	public int getConfirmationsLeftToPrint() {
		return privateconfirmationsLeftToPrint;
	}

	/**
	 * Prints confirmation that credit card was withheld.
	 * 
	 * @return true
	 */
	public boolean printCardWithheldConfirmation() {
		if (checkPaper()) {
			setConfirmationsLeftToPrint(getConfirmationsLeftToPrint() - 1);
			System.out.println(">> Printer: This is a confirmation that your card was withheld.");
			return true;
		}
		return false;
	}

	/**
	 * Prints transaction confirmation.
	 * 
	 * @param amount
	 *            Amount of transaction
	 * @return true
	 */
	public boolean printTransactionConfirmation(int amount) {
		if (getConfirmationsLeftToPrint() > 0 && amount > 0) {

			setConfirmationsLeftToPrint(getConfirmationsLeftToPrint() - 1);
			System.out.printf(">> Printer: This is a confirmation that DKK %1$s was withdrawn from your account." + "\r\n", amount);
			return true;
		}
		return false;
	}

	private void setConfirmationsLeftToPrint(int value) {
		privateconfirmationsLeftToPrint = value;
	}

}
